<?php
class Hydrum_Module_Collection implements Iterator
{
    protected $_items;

    public function set($index, $value)
    {
        $this->_items[$index] = $value;

        return $this;
    }

    public function get($index)
    {
        if (isset($this->_items[$index])) {
            return $this->_items[$index];
        } else {
            throw new Exception('Can\'t find module with name "' . $index . '"');
        }
    }

    public function rewind()
    {
        return reset($this->_items);
    }

    public function current()
    {
        return current($this->_items);
    }

    public function key()
    {
        return key($this->_items);
    }

    public function next()
    {
        return next($this->_items);
    }

    public function valid()
    {
        return key($this->_items) !== null;
    }
}
